<?php
namespace app\organize\admin;
use app\admin\controller\Admin;
use app\organize\model\department as DepartmentModel;
use \think\Request;

class Department extends Admin
{
	public $tab_data = [];
	public $param = [];

    /**
     * 初始化方法
     */
    protected function _initialize()
    {
        parent::_initialize();

	    $tab_data['menu'] = [
	        [
	            'title' => '已启用模块',
	            'url' => 'admin/module/index?status=2',
	        ],
	        [
	            'title' => '未启用模块',
	            'url' => 'admin/module/index?status=1',
	        ],
	        [
	            'title' => '未安装模块',
	            'url' => 'admin/module/index?status=0',
	        ],
	        [
	            'title' => '导入模块',
	            'url' => 'admin/module/import',
	        ],
	    ];
	    if (config('develop.app_debug') == 1) {
	        array_push($tab_data['menu'], ['title' => '设计新模块', 'url' => 'admin/module/design',]);
	    }
	    $this->tab_data = $tab_data;
	}

    public function index()
    {
    	$depart_data = DepartmentModel::getDepartmentList();
    	$default_depart_id = $depart_data['id'];
    	cache('default_depart_id',$default_depart_id);
    	$this->assign('depart_data',json_encode(array($depart_data)));
    	$this->assign('default_depart_id',$default_depart_id);
        return $this->afetch();
    }

    public function staff()
    {
        // if ($this->request->isPost()) {
        //     $data = $this->request->post();
        //     // 验证
        //     $result = $this->validate($data, 'AdminUser');
        //     if($result !== true) {
        //         return $this->error($result);
        //     }
        // }
    	$current_depart_id = isset($this->param['depart_id'])?$this->param['depart_id']:cache('default_depart_id');
    	cache('current_depart',$current_depart_id);
    	$page = isset($this->param['page'])?$this->param['page']:1;
    	$pageSize = isset($this->param['limit'])?$this->param['limit']:10;
    	$user_ret = DepartmentModel::getUserByDepartId($current_depart_id , $page, $pageSize);
    	return ['code'=>0,'msg'=>'','count'=>$user_ret['count'],'data'=>$user_ret['data']];
    }
}